<?php

//<editor-fold defaultstate="collapsed" desc="License & Copyright">
/*
 * @license
 */

/**
 *
 * @author Jevgeni Geimanen (jevgeni.geimanen@gmail.com)
 */
//</editor-fold>
class SCFormFieldCollection extends ComponentCollection {

    /**
     *
     * @param string $name
     * @return TextFormField 
     */
    public function NewTextField($name) {
        $res = new TextFormField();
        $res->setControlName($name);
        $this->Add($res);
        return $res;
    }

    /**
     *
     * @param string $name
     * @param string  $type
     * @param string  $label
     * @param array $validators
     * @return FormField
     */
    protected function AddFormField($name, $type, $label = null, $validators = array()) {
        $res = new $type();
        $res->setControlName($name);
        $vals = $this
                ->Add($res)
                ->setLabel($label)
                ->getValidators();
        foreach ($validators as $validator)
            $vals->Add($validator);
        return $res;
    }

    
    /**
     *
     * @var ButtonFormField
     */
    private $_SubmitButton = null;

    /**
     *
     * @param string $name
     * @param string $label
     * @return ButtonFormField
     */
    public function getSubmitButton($name = 'Submit', $label = 'Submit') {
        if ($this->_SubmitButton === null) {
            $this->_SubmitButton = $this
                    ->AddFormField($name, 'ButtonFormField', $label)
                    ->setButtonType(SCButtonFormField::BUTTON_TYPE_SUBMIT);
        }
        return $this->_SubmitButton;
    }

    /**
     *
     * @var ButtonFormField
     */
    private $_ResetButton = null;

    /**
     *
     * @param string $name
     * @param string $label
     * @return ButtonFormField
     */
    public function getResetButton($name = 'Reset', $label = 'Reset') {
        if ($this->_ResetButton === null) {
            $this->_ResetButton = $this
                    ->AddFormField($name, 'ButtonFormField', $label)
                    ->setButtonType(SCButtonFormField::BUTTON_TYPE_RESET);
        }
        return $this->_ResetButton;
    }

}

?>
